document.addEventListener('DOMContentLoaded', function() {
    const keyword = sessionStorage.getItem('searchKeyword');
    const container = document.getElementById('search-results-container');
    
    if (!keyword || !container) {
        container.innerHTML = '<p>请输入搜索关键词</p>';
        return;
    }

    // 模拟搜索（实际项目应使用AJAX请求后端）
    const mockProducts = [
        { id: 1, name: '商品名称1', price: 199, image: 'images/product1.jpg' },
        { id: 2, name: '商品名称2', price: 299, image: 'images/product1.jpg' }
    ];

    const results = mockProducts.filter(product => 
        product.name.includes(keyword)
    );

    if (results.length === 0) {
        container.innerHTML = `<p>没有找到包含"${keyword}"的商品</p>`;
    } else {
        container.innerHTML = results.map(product => `
            <div class="product-card">
                <a href="product.html?id=${product.id}">
                    <img src="${product.image}" alt="${product.name}">
                    <h3>${product.name}</h3>
                    <p class="price">¥${product.price.toFixed(2)}</p>
                </a>
                <button class="add-to-cart" data-id="${product.id}">加入购物车</button>
            </div>
        `).join('');
        
        // 重新绑定购物车按钮事件
        document.querySelectorAll('.add-to-cart').forEach(btn => {
            btn.addEventListener('click', function() {
                addToCart(this.getAttribute('data-id'));
            });
        });
    }
});

// 复用购物车功能
function addToCart(productId) {
    // ... (与main.js中的addToCart相同实现)
}